package com.ruoyi.app.controller.member.mapper;

import com.ruoyi.app.controller.member.entity.BO.MemberDetailBO;
import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.member.MemberDO;
import com.ruoyi.common.entity.VO.member.MemberVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface IMemberMapper extends BaseMapper<MemberDO> {

    @Select("SELECT id,shop_id shopId,openid,avatar,nickname,salt FROM member WHERE openid=#{openid}")
    MemberDO getMemberByOpenid(String openid);

    @Select("SELECT count(1) FROM member WHERE openid=#{openid} and id=#{memberId}")
    int countByOpenidAndId(@Param("openid") String openid,@Param("memberId") Long memberId);

    @Select("SELECT m.id,avatar,avatar_w avatarW,nickname,phone,user_name userName,sex,birthday,vip_type_id vipTypeId,vip_type_name vipTypeName,vip_type_logo vipTypeLogo FROM member m left join member_vip_type mv on m.vip_type_id=mv.id WHERE m.id=#{memberId}")
    MemberVO getProfileById(Long memberId);

    @Select("SELECT m.id,m.shop_id shopId,avatar,avatar_w avatarW,nickname,phone,user_name userName,sex,birthday,vip_type_id vipTypeId,vip_type_name vipTypeName,vip_type_logo vipTypeLogo,balance,credit,commission,total_recharge_amount totalRechargeAmount,total_petrol_amount totalPetrolAmount FROM member m left join member_vip_type mv on m.vip_type_id=mv.id WHERE m.id=#{memberId}")
    MemberDetailBO getDetailById(Long memberId);

    @Select("SELECT id,openid,phone,vip_type_id vipTypeId,balance,credit,commission,total_recharge_amount totalRechargeAmount,total_petrol_amount totalPetrolAmount FROM member WHERE id=#{memberId}")
    MemberDO getAssetById(Long memberId);

    @Select("SELECT id,salt,paypassword FROM member WHERE id=#{memberId}")
    MemberDO getPasswordInfoById(Long memberId);

    @Select("SELECT id,shop_id shopId,openid FROM member ORDER BY RAND() LIMIT 1")
    MemberDO getRandomMember();

    @Select("SELECT id,shop_id shopId,openid FROM member WHERE id = #{memberId}")
    MemberDO getForTokenById(Long memberId);

    @Select("SELECT COUNT(1) FROM member WHERE date_format(create_time,'%y%m%d') = date_format(sysdate(),'%y%m%d')")
    int getTodayCount();

    @Select("SELECT COUNT(*) FROM member WHERE shop_id=#{shopId} and DATE_FORMAT(create_time, '%Y-%m')=DATE_FORMAT(NOW(), '%Y-%m')")
    int countMemberCurrentMonth(Long shopId);

    @Select("SELECT COUNT(*) FROM member WHERE shop_id=#{shopId} and DATE_FORMAT(create_time, '%Y-%m-%d') >= DATE_FORMAT(#{startDay}, '%Y-%m-%d') and DATE_FORMAT(create_time, '%Y-%m-%d')<=DATE_FORMAT(#{endDay}, '%Y-%m-%d')")
    int countMemberBetweenDay(@Param("startDay") String startDay,@Param("endDay") String endDay,@Param("shopId") Long shopId);

    @Select("SELECT vip_type_id FROM member WHERE id = #{memberId}")
    Long getMemberVipIdById(Long memberId);
}
